package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/4/6 16:45
 */
public class Sword14_I {

    /**
     * dp[i]表示：长度为i的绳子剪成m段后最大的乘积。
     * @param n
     * @return
     */
    public static int cuttingRope(int n) {
        int[] dp = new int[n + 1];
        dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            for (int j = 1; j <= i - 1; j++) {
//                System.out.println("i = " + i + " j*(i-j)：" + j * (i - j) + "  j*dp[i-j] " + j * dp[i - j] + "   dp[i-j]：" + (i - j));
                dp[i] = Math.max(dp[i], Math.max(j * (i - j), j * dp[i - j]));
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        int i = cuttingRope(1000);
        System.out.println(i);
    }
}
